package com.kiss.rpc.discovery;

import com.kiss.rpc.Constant;
import com.kiss.rpc.discovery.impl.ZooKeeperRegistry;
import com.kiss.rpc.exceptions.DiscoveryException;

public class RegistryConfig {

    private final String connectString;

    public RegistryConfig(String connectString) {
        this.connectString = connectString;
    }

    public Registry getRegistry() {
        String registryType = connectString.split(":")[0];
        String host = connectString.split(":")[1].split("/")[2];
        if (registryType.equals("zookeeper")) {
            return new ZooKeeperRegistry(host, Constant.TIME_OUT);
        }
        else if (registryType.equals("nacos")) {
            throw new DiscoveryException("nacos注册中心还没有实现");
        }
        else {
            throw new DiscoveryException("不支持的注册中心：" + registryType);
        }
    }
}
